Skip to content

feat: Support Draft-04 in strict mode - #1002

Open
Roman3349 wants to merge 7 commits into
jsonrainbow:mainfrom
Roman3349:feat/draft-04-strict-mode
Open

Roman3349 wants to merge 7 commits into
jsonrainbow:mainfrom
Roman3349:feat/draft-04-strict-mode

Conversation

@Roman3349

@Roman3349 Roman3349 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

CHECK_MODE_STRICT could not be used with Draft-04 schemas. The validator looked up a draft04 constraint that did not exist and threw Unknown constraint draft04, so Draft-04 schemas could only be validated by the legacy constraints.

This adds a Draft-04 constraint set for the strict mode. Following the existing pattern, the classes are full copies of the Draft-06 classes, not subclasses, and no Draft-06 or later file is changed. Without CHECK_MODE_STRICT, Draft-04 schemas are still validated by the legacy constraints.

The copies only differ from Draft-06 where the Draft-04 specification does:

  • const, contains, propertyNames and the numeric exclusiveMinimum/exclusiveMaximum keywords do not exist in Draft-04 and are not part of the set.
  • exclusiveMinimum/exclusiveMaximum are boolean modifiers of minimum/maximum (validation §5.1.2, §5.1.3). Without minimum/maximum they are ignored. A failed exclusive bound is reported as exclusiveMinimum/exclusiveMaximum.
  • integer is a JSON number without a fraction or exponent part (core §3.5), so a float such as 1.0 is not an integer.
  • As in the other drafts since fix: Validate the schema against its meta-schema in strict mode #973, the schema is validated against the Draft-04 meta-schema when CHECK_MODE_VALIDATE_SCHEMA is set.

Changes:

  • Constraints\Drafts\Draft04: new constraint set, its Factory and the draft04 entry in Constraints\Factory.
  • JsonSchemaTestSuiteTest: the Draft-04 test suite runs in strict mode too, next to the existing run with the legacy constraints. The strict mode run has its own skips, 17 cases (bignum, float overflow, zero-width whitespace in \s and the known format gaps of the other drafts). All of them are skipped for the legacy constraints too. Another 26 cases that are skipped for the legacy constraints pass in strict mode: 24 ECMA 262 regex cases and multipleOf with a small and a large number.
  • Tests: the Draft-06 unit tests are copied to tests/Constraints/Draft04, plus Draft04ConstraintTest for the Draft-04 specific behavior. Draft-04 is added to the strict mode cases in SchemaValidationTest and removed from the drafts without strict mode support in ValidatorTest.
  • README.md: Draft-4 is listed in the CHECK_MODE_STRICT footnote.

Related Issue

None

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

This PR also contains the commits of other open PRs, so that Draft-04 in strict mode gets their fixes too. The last commit applies them to the Draft-04 classes and removes the strict mode skips that pass now:

Once those are merged, their commits drop out of this PR when it is rebased. With them, 4 cases are skipped for Draft-04 in strict mode (bignum, float overflow and the overall length of a hostname), instead of the 17 listed above.

…RFC 3986 and RFC 5321

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
… address literals

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
@Roman3349
Roman3349 force-pushed the feat/draft-04-strict-mode branch from dd06351 to 3e81507 Compare December 4, 2026 14:37
…t mode on 32 bits

Signed-off-by: Roman Ondráček <mail@romanondracek.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant